<?php
/**
 * Description of myWidgetFormSelectCheckboxTable
 *
 * @author Tazenda
 */
class myWidgetFormSelectRadio extends sfWidgetFormSelectRadio {
    
    protected function formatChoices($name, $value, $choices, $attributes)
    {
        $inputs = array();
        foreach ($choices as $key => $option)
        {
            $baseAttributes = array(
                    'name'  => substr($name, 0, -2),
                    'type'  => 'radio',
                    'value' => self::escapeOnce($key),
                    'id'    => $id = $this->generateId($name, self::escapeOnce($key)),
                );

            if (strval($key) == strval($value === false ? 0 : $value))
            {
                $baseAttributes['checked'] = 'checked';
            }

            $inputs[$id] = array(
                    'input' => $this->renderTag('input', array_merge($baseAttributes, $attributes)),
                    'label' => $this->renderContentTag('p', self::escapeOnce($option), array('for' => $id, 'class' => 'voting-option-label')),
                    'image' => Doctrine::getTable('Candidate')->find($key)->getImage()
                );
        }

        return call_user_func($this->getOption('formatter'), $this, $inputs);
    }
    
    public function formatter($widget, $inputs) { 
        $rows = array(); 
        $itemsPerRow = 5; 
        $i=0; 
        $count = count($inputs);
        foreach ($inputs as $input) { 
            $rows[] = $this->renderContentTag(
                'div', 
                $input['input'].$this->getOption('label_separator').$input['label'],
                array('style' => "background: url('/uploads/".$input['image']."') no-repeat;")
            );
        } 
        return !$rows ? '' 
                : 
                $this->renderContentTag(
                    'div', 
                    implode($this->getOption('separator'), $rows), 
                    array(
                        'class' => 'radio_list span-17 last' //$this->getOption('class')
                    )
                ); 
    } 
}

?>
